package com.munchkinquest.utils;

import com.munchkinquest.Constants;
import com.munchkinquest.beans.Player;
import com.munchkinquest.beans.StepBean;
import java.lang.reflect.Method;
import com.munchkinquest.model.Step;
import com.munchkinquest.model.Stepbtn;
import java.util.ResourceBundle;

/**
 * Manages button actions for more involved steps other than Next or Yes/No clicks.
 * @author stephen
 */
public class ButtonManager {

    public static final int HI_LINK = 3;

    public static Long doneSearch(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.lowerMovement();
        return stepBtn.getNextstepid();
    }

    public static Long checkIfMovesLeft(Stepbtn stepBtn, Player player, StringBuilder page) {
        if (player.isOutOfMoves()) {
            return SpecialSteps.getSpecialStep(Constants.MONSTERS_TURN);
        } else {
            return stepBtn.getNextstepid();
        }
    }

    public static Long died(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.die();
        return stepBtn.getNextstepid();
    }

    public static Long starting(Stepbtn stepBtn, Player player, StringBuilder page) {
        if (player.isDead()) {
            return SpecialSteps.getSpecialStep(Constants.RETURN_TO_LIFE);
        } else {
            player.resetMovement();
            return stepBtn.getNextstepid();
        }
    }

    public static Long revive(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.revive();
        return stepBtn.getNextstepid();
    }

    public static Long endTurn(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.endTurn();
        return stepBtn.getNextstepid();
    }

    public static Long checkLinkMovementCost(Stepbtn stepBtn, Player player, StringBuilder page) {
        if (HI_LINK <= player.getMovement() || !player.isAlreadyExitedRoomThisTurn()) {
            player.lowerMovementBy3();
            player.setAlreadyExitedRoomThisTurn(true);
            return stepBtn.getNextstepid();
        } else {
            return SpecialSteps.getSpecialStep(Constants.NOT_ENOUGH_MOVES_TO_EXIT);
        }
    }

    public static Long moveThroughLinkVal1(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.lowerMovement();
        player.setAlreadyExitedRoomThisTurn(true);
        return stepBtn.getNextstepid();
    }

    public static Long takeDamage(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.lowerHealth();
        if (player.isDead()) {
            return SpecialSteps.getSpecialStep(Constants.DIE);
        } else {
            return stepBtn.getNextstepid();
        }
    }

    public static Long lowerMovementAndCheck(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.lowerMovement();
        if (player.isOutOfMoves()) {
            return SpecialSteps.getSpecialStep(Constants.MONSTERS_TURN);
        } else {
            return stepBtn.getNextstepid();
        }
    }

    public static Long endMonsterTurnCheck(Stepbtn stepBtn, Player player, StringBuilder page) {
        if (player.isOutOfMoves()) {
            return SpecialSteps.getSpecialStep(Constants.END_OF_ROUND);
        } else {
            return stepBtn.getNextstepid();
        }
    }

    public static Long initPlayer(Stepbtn stepBtn, Player player, StringBuilder page) {
        player.revive();
        page = page.append("initialise");        
        return 0L;
    }
}